const http = require('http');
const server = http.createServer();

server.on('request',(req,res)=>{
    const url = req.url
    // 设置默认的响应内容为 404 Not found
    let content = '404 Not found!'

    if(url == '/' || url == 'index.html'){
        content = '<h1>首页</h1>'
    }else if(url == '/about.html'){
        content = '<h1>关于页面</h1>'
    }else{
        content = '404 Not found!'
    }
    // 设置 防止中文乱码
    res.setHeader('Content-Type','text/html; charset=utf-8')
    res.end(content)
})

server.listen('80',()=>{
    console.log('server runing at http://127.0.0.1');
})